#include<iostream>
using namespace std;

class X
{
	public:
		X();
		X(int);
		X(const X&);
		~X();
		void setA(int);
		int getA() const;
		X& operator=(const X&);
	private:
		int a;
};

X::X()
{
	cout << "X default constructor" << endl;
}

X::X(int i)
{
	a = i;
	cout << a << " constructed" << endl;
}

X::X(const X& x)
{
	cout << "copy constructed from " << x.getA() <<endl;
}

X::~X()
{
	cout << a << " destructed" << endl;
}

void X::setA(int aa)
{
	a = aa;
}

int X::getA() const
{
	return a;
}

X& X::operator=(const X& xx)
{
	a = xx.getA();
	cout << "copy operator from " << xx.getA() <<endl;
}

////////////////////////////////////////////////
class Y
{
	public:
		Y();
	private:
		X x;
};

Y::Y()//:x(10)
{
	x = 10;
	x.setA(20);
}

////////////////////////////////////////////////
X foo()
{
	X x1(1);
	X x2(2);
	return x1;	
}

///////////////////////////////////////////////
int main(int argc, char* argv[])
{
	cout<<"========================="<<endl;
	X x3 = foo(); //x3 and x1 turn to be one by NRV optimization
	X x4 = x3;
//	Y y;
	cout<<"========================="<<endl;
	return 0;
}
